<?php
namespace GuessStar\Controller;
use  Common\Controller\GuessStarController;
class TestController extends GuessStarController {


    //随机上下左右
   public function test(){
        eixt;
       $question = M('star_question1')->select();

       $suiji = $this->shuffle_assoc($question);
       $suiji = $this->shuffle_assoc($suiji);
       $suiji = array_merge($suiji);

       $data1= array();
       $i=0;

       foreach ($suiji as $key=>$val){

           $i++;
           $data1 = array(
               'a' => $val['puzzle1'],
               'b' => $val['puzzle2'],
               'c' => $val['puzzle3'],
           );

           shuffle($data1);

           $data = array(
               'answer'=>$val['answer'],
               'category'=>$val['category'],
               'imgsrc'=>$val['imgsrc'],
               'sort'=>$i,
               'puzzle1'=>$data1[0],
               'puzzle2'=>$data1[1],
               'puzzle3'=>$data1[2]
           );
           M('star_question3')->data($data)->add();
           echo 0;

       }


   }

   public function insert(){
        exit;
       $question = M('star_question3')->select();
       $i = 488;
       foreach ($question as $key=>$value){
           $i++;
           $data = array(
               'answer'=>$value['answer'],
               'category'=>$value['category'],
               'imgsrc'=>$value['imgsrc'],
               'sort'=>$i,
               'puzzle1'=>$value['puzzle1'],
               'puzzle2'=>$value['puzzle2'],
               'puzzle3'=>$value['puzzle3']
           );

           M('star_question')->data($data)->add();

       }

   }

    //随机左右
    public function starqustion(){
        exit;
        $quersion = M('star_question1')->field('star_question_id,puzzle1,puzzle2,puzzle3')->select();


        $data = array();
        $i=0;
        foreach ($quersion as $value) {
            $i++;
            $data = array(
                'a' => $value['puzzle1'],
                'b' => $value['puzzle2'],
                'c' => $value['puzzle3'],
            );

            shuffle($data);

            $arr = array(
                'puzzle1' => $data[0],
                'puzzle2' => $data[1],
                'puzzle3' => $data[2],
                'sort'=>$i,
            );

            M('star_question1')->where(array('star_question_id' => $value[star_question_id]))->save($arr);

        }

    }


    //验证文件是否存在,存在则移到另一处
    public function chefile(){

       exit;
       $question = M('star_question1')->field('imgsrc')->select();

       foreach ($question as $key=>$value){

           $img = 'Public/data/image/'.$value['imgsrc'];
           $newimage =  'Public/data/newimage/'.$value['imgsrc'];
           if (file_exists($img)){
               copy($img,$newimage);
               echo '0'.'<br>';
           }

       }


    }



}
